<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2020/9/29
 * Time: 15:07
 */

namespace app\api\controller;


use language\Languagemsg;
use think\Db;

class Set extends Base
{
    private $user_id; // 用户ID
    private $page; // 页码
    private $create_time;
    
    /**
     * 异地登录验证
     * @return string
     */
    public function __construct()
    {
        $this->msg_language = new Languagemsg();
        $this->language = input('language') ? input('language') : 0;
        $this->user_id = input('user_id');
        $this->page = input('page') ? input('page') : 1;
        $this->create_time = date('Y-m-d H:i:s');
        $time = input('time');
        $value = input('value');
        $reqKey = input('reqKey');
        $auth = $this->checkAll($this->user_id, $time, $value, $reqKey);
        if($auth == 112){
            echo json_encode(['status'=>301, 'msg'=>$this->msg_language->otherLogin[$this->language]]);
            exit;
        }elseif($auth == 2111){
            echo json_encode(['status' => 303, 'msg' => $this->msg_language->frost[$this->language]]);
            exit;
        }
    }
    
    /**
     * 常见问题
     * @return \think\response\Json
     */
    public function commonProblem(){
        $problem = Db::table('up_problem')->field('problem_id, problem_title')->order('problem_time desc')->select();
        if($problem){
            return json(['status' => 200, 'msg' => $problem]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }
    }
    
    /**
     * 问题内容
     * @return \think\response\Json
     * problem_id     问题ID
     */
    public function problemContent(){
        $problem_id = input('problem_id');
        $content = Db::table('up_problem')->where('problem_id', $problem_id)->value('problem_content');
        return json(['status' => 200, 'msg' => $content]);
    }
    
    /**
     * 联系我们
     * @return \think\response\Json
     */
    public function connectUs(){
        $value = Db::table('up_other')->where('other_id', 7)->field('other_call_us')->find();
        $value1 = Db::table('up_other')->where('other_id', 4)->field('other_phone, other_email, other_link')->find();
        return json(['status' => 200, 'msg' => $value, 'connect' => $value1]);
    }
    
    /**
     * 意见反馈
     * @return \think\response\Json
     * feedback_content       反馈内容
     * feedback_phone         手机号
     */
    public function feedback(){
        $feedback_content = input('feedback_content');
        $feedback_phone = input('feedback_phone');
        $insert = [
            'fd_user_id' => $this->user_id,
            'fd_content' => $feedback_content,
            'fd_phone' => $feedback_phone,
            'fd_time' => $this->create_time
        ];
        $res = Db::table('up_feedback')->insert($insert);
        if($res){
//            return json(['status' => 200, 'msg' => '提交成功']);
            return json(['status' => 200, 'msg' => $this->msg_language->commitSuccess[$this->language]]);
        }else{
//            return json(['status' => 0, 'msg' => '系统异常，请稍后重试']);
            return json(['status' => 0, 'msg' => $this->msg_language->systemErr[$this->language]]);
        }
    }
    
    /**
     * 关于我们
     * @return \think\response\Json
     */
    public function aboutUs(){
        $gn = Db::table('up_other')->where('other_id', 6)->value('other_gn_desc');
        $fl = Db::table('up_other')->where('other_id', 3)->value('other_falv');
        $pt = Db::table('up_other')->where('other_id', 5)->value('other_pt_agreement');
        return json(['status' => 200, 'msg' => '', 'gn' => $gn, 'fl' => $fl, 'pt' => $pt]);
    }
}